package com.zhn.evsi.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhn.evsi.domain.dto.Market.MarketOrderDTO;
import com.zhn.evsi.domain.dto.Market.MarketOrderSearchDTO;
import com.zhn.evsi.domain.entity.Market.MarketOrder;
import com.zhn.evsi.mapper.MarketOrderMapper;
import com.zhn.evsi.service.IMarketOrderService;
import oracle.jrockit.jfr.jdkevents.ThrowableTracer;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MarketOrderServiceImpl extends ServiceImpl<MarketOrderMapper, MarketOrder> implements IMarketOrderService {

    /**
     * 商品列表list查询
     *
     * @param marketOrderDTO - 模糊查询
     * */
    @Override
    public List<MarketOrder> orderList(MarketOrderDTO marketOrderDTO) {
        return this.list();
    }

    /**
     * 新增输入商品名称自动填充
     *
     * @param search - 模糊查询自动填充字段
     * */
    @Override
    public List<MarketOrderSearchDTO> search(String search) {
        // 字段进行处理
        StringBuilder stringBuilder = new StringBuilder(search);

        // 模糊查询处理
        for (int i = search.length(); i >= 0; i--){
            stringBuilder.insert(i, "%");
        }
        return this.baseMapper.search(stringBuilder.toString());
    }

    @Override
    public void addOrders(MarketOrderDTO marketOrderDTO) {
        // 将实体类复制
        MarketOrder marketOrder = new MarketOrder();
        BeanUtil.copyProperties(marketOrder, marketOrderDTO);
        // 物品新增
        this.saveOrUpdate(marketOrder);

    }
}
